package com.bear.atlassianmcp.jira.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

/**
 * Jira搜索结果数据模型
 * 对应Jira REST API搜索接口返回的结果
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class JiraSearchResult {

    private String expand;
    private int startAt;
    private int maxResults;
    private int total;
    private List<JiraIssue> issues;

    /**
     * 格式化为AI友好的文本描述
     */
    public String toFormattedString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Search Results: ").append(total).append(" total issues found\n");
        sb.append("Showing: ").append(startAt + 1).append("-").append(Math.min(startAt + maxResults, total)).append("\n\n");
        
        if (issues != null && !issues.isEmpty()) {
            for (int i = 0; i < issues.size(); i++) {
                JiraIssue issue = issues.get(i);
                sb.append(i + 1).append(". ").append(issue.getKey()).append(" - ").append(issue.getSummary()).append("\n");
                sb.append("   Status: ").append(issue.getStatus());
                sb.append(", Type: ").append(issue.getIssueType());
                sb.append(", Assignee: ").append(issue.getAssignee()).append("\n");
            }
        } else {
            sb.append("No issues found.\n");
        }
        
        return sb.toString();
    }

    /**
     * 获取简化的Issue列表描述
     */
    public String toSimpleList() {
        if (issues == null || issues.isEmpty()) {
            return "No issues found.";
        }
        
        StringBuilder sb = new StringBuilder();
        sb.append("Found ").append(total).append(" issues:\n");
        
        for (JiraIssue issue : issues) {
            sb.append("- ").append(issue.getKey()).append(": ").append(issue.getSummary()).append("\n");
        }
        
        return sb.toString();
    }

    // Getters and Setters
    public String getExpand() {
        return expand;
    }

    public void setExpand(String expand) {
        this.expand = expand;
    }

    public int getStartAt() {
        return startAt;
    }

    public void setStartAt(int startAt) {
        this.startAt = startAt;
    }

    public int getMaxResults() {
        return maxResults;
    }

    public void setMaxResults(int maxResults) {
        this.maxResults = maxResults;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public List<JiraIssue> getIssues() {
        return issues;
    }

    public void setIssues(List<JiraIssue> issues) {
        this.issues = issues;
    }
}
